using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using QuanLyThuVien1.DTO;

namespace QuanLyThuVien1.DAO
{
    public class DAUSACH_DAO
    {
        public DataTable layDS()
        {
            DataTable dtDS = new DataTable();
            OleDbConnection oledbcnKetnoi = KETNOI.taoKetNoi() ;


            string sChuoitruyvan = "SELECT * FROM DAUSACH";
            OleDbCommand oledbcmTruyvan = new OleDbCommand(sChuoitruyvan, oledbcnKetnoi);


            OleDbDataAdapter oledbapt = new OleDbDataAdapter(oledbcmTruyvan);
            oledbapt.Fill(dtDS);

            oledbcnKetnoi.Close();
            oledbcnKetnoi.Dispose();
            oledbcmTruyvan.Dispose();
            oledbapt.Dispose();

            return dtDS;

        }
        public DAUSACH timDS(string maDS)
        {
            OleDbConnection connect = KETNOI.taoKetNoi();
            DAUSACH danhSach = null;
            string connecstr = "select * from DAUSACH where maDauSach = " + maDS;
            OleDbCommand command = new OleDbCommand(connecstr, connect);
            command.ExecuteNonQuery();
            OleDbDataReader Reader = command.ExecuteReader();
            if (Reader.Read())
            {
                danhSach = new DAUSACH();
            }
            connect.Close();
            return danhSach;
        }
        public void XoaDS(string maDS)
        {
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "delete from DAUSACH where maDauSach = " + maDS;
            OleDbCommand command = new OleDbCommand(connecstr,connect);
            command.ExecuteNonQuery();
            connect.Close();
        }
        public void ThemVaoDauSach(DAUSACH d)
        {
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "insert into DAUSACH values('"+d.MADAUSACH+"','"+d.TENDAUSACH+"','"+d.SoTap+"')";
            OleDbCommand command = new OleDbCommand(connecstr, connect);
            command.ExecuteNonQuery();
            connect.Close();
        }
        public bool TimDauSach(string maDS)
        {
            DataTable d = new DataTable();
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "select * from DauSach where maDauSach = '" + maDS + "'";
            OleDbDataAdapter adapter = new OleDbDataAdapter(connecstr, connect);
            adapter.Fill(d);
            connect.Close();
            if (d.Rows.Count > 0)
                return true;
            return false;
        }
    }
}
